package com.ych.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ych.beans.Message;
import com.ych.beans.Orga;
import com.ych.dao.OrgaDao;
import com.ych.service.OrgaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrgaServiceImpl implements OrgaService {
    @Autowired
    OrgaDao dao;
    @Override
    public Message selectOrg(Integer pageNo, String key) {
        Message message = new Message();
        if(pageNo!=null){
            PageHelper.startPage(pageNo, 8);
        }
        List<Orga> list=dao.selectOrg(key);
        final PageInfo<Orga> objectPageInfo = new PageInfo<>(list);
        if(!list.isEmpty()){
            message.setSuccess(true);
            message.setObj(objectPageInfo);
        }
        return message;
    }

    @Override
    public Message addOrg(Orga orga) {
        final Message message = new Message();
        boolean flag = dao.addOrg(orga);
        message.setSuccess(flag);
        if (flag){
            message.setMsg("添加成功");
        }else {
            message.setMsg("添加失败");
        }
        return message;
    }
}
